package com.summary.utils;

import java.util.List;

public class PaginationUtils {
    public static <T> List<T> getPage(List<T> list, int pageSize, int pageNum) {
        int totalItems = list.size();
        int totalPages = (int) Math.ceil((double) totalItems / pageSize);

        if (pageNum <= 0 || pageNum > totalPages) {
            throw new IllegalArgumentException("Invalid page number: " + pageNum);
        }

        int fromIndex = (pageNum - 1) * pageSize;
        int toIndex = Math.min(fromIndex + pageSize, totalItems);

        return list.subList(fromIndex, toIndex);
    }
}
